package com.klangner.go.app;

import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;

public abstract class GeneralOKCancel extends Frame {
    Panel panel2 = null;
    Button btnOK = null;
    Button btnClose = null;

    public GeneralOKCancel() {
        panel2 = new Panel();
        btnOK = new Button();
        btnClose = new Button();

        try  {
            jbInit();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setSize(new Dimension(361, 305));

        btnOK.setLabel("OK");

        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
            btnOK_actionPerformed(e);
            }
        });

        btnClose.setLabel("Close");

        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
            btnClose_actionPerformed(e);
            }
        });

        this.add(panel2, BorderLayout.SOUTH);
        panel2.add(btnOK, null);
        panel2.add(btnClose, null);

        this.addWindowListener(new WindowAdapter () {
            public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
            }
        });
    }

    // load components values from the related object
    abstract protected void loadData();

    // save changes to the related object
    abstract protected void saveChanges();

    void btnClose_actionPerformed(ActionEvent e) {
        formClose();
    }

    void btnOK_actionPerformed(ActionEvent e) {
        saveChanges();
        formClose();
    }

    private void formClose() {
        this.setVisible( false );
    }
}

